function QueMessage(arg, clear)
% Quemessage puts a message in the "QueMessage" listbox.
% the clear flag, if present, causes the box to be emptied before writing
%
% old version, but updated 4/2008 P. Manis
%

hqm=findobj('Tag','QueMessage');
if(~ishandle(hqm)) % if no text box, just print to the command window instead
    fprintf(1, 'Program Message: %s\n', arg);
    return;
end;

if(nargin > 1 && clear == 1)
    a={}; % clear the list box string
    if(~isempty(arg))
        a{1} = arg;
    else
        a{1} = 'matlab datac';
    end
else
    a = get(hqm, 'String');
    n = length(a);
    if(ischar(a))
        a = strvcat(a, arg); %#ok<VCAT>
    end;
    if(iscell(a))
        a{n+1} = arg;
    end;
end

% now update the list box.
u=size(a, 1);
set(hqm, 'String', a);
if(u <= 4)
    set(hqm, 'Listboxtop', 1);
else
    set(hqm, 'ListboxTop', u-4);
end;

set(hqm, 'Min', 1); % always make sure the min/max is set.
set(hqm, 'Max', u);

drawnow
return
